package main

import (
	"fmt"
	"math/rand"
)

func main() {

	nineNineTable()
	fmt.Println("---------------------------------------")
	rands()
	fmt.Println("---------------------------------------")
	bf()
}

// 随机生成20以内的20个非0正整数，打印出来。对生成的数值，第单数个（不是索引）累加求和，第偶数个累乘求积。打印结果
func rands() {
	var ints [20]int
	counts := 0
	products := 1
	for i := 0; i < 20; i++ {
		ints[i] = rand.Intn(20)

		for { //使随机不为0
			if ints[i] == 0 {
				ints[i] = rand.Intn(20)
			} else {
				break
			}
		}
		th := i + 1 //第th个值

		if th%2 == 0 { //如果第th % 2 == 0 ，为第偶数个，打印出 偶数个之间的积
			products *= ints[i]
			fmt.Printf("第%v个值为: %v\t为第偶数个\t 偶数个间的积为: %v\n", th, ints[i], products)
		} else if th%2 == 1 { //其他则为为第奇数个，打印出 奇数个之间的和
			counts += ints[i]
			fmt.Printf("第%v个值为: %v\t为第奇数个\t 奇数间的和为: %v\n", th, ints[i], counts)
		} else {
			panic(th)
		}

	}
}

// 九九乘法表
func nineNineTable() {
	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%v * %v = %v\t", j, i, i*j)
		}
		fmt.Println()
	}
}

// 100以内的斐波那契数列;
func bf() {
	fmt.Print("100以内的斐波那契数列;   ")
	a2 := 1 //前前的值
	a1 := 1 //前的值
	fmt.Print(a2, " ")
	fmt.Print(a1, " ")
	for i := 1; i < 100; i++ {
		aa := a2 + a1
		if aa >= 100 {
			break //大于100就退出
		}
		fmt.Print(aa, " ")
		a2 = a1
		a1 = aa
	}
}
